(function(){
	var vm=new Vue({
		el:"#wrapper",
		data: {
		    sChangePwdTip: '',
		    userName: '',
            UserInfo: { Mobile: '', Password: '', ValidateCode: '' },
            loginInfo: { isLogin: '', name: '', mobile: '' },
            p_obj: { url: 'logo', text: '提示文字' },
            nextStepDisable: true,
            sureDisable: true,
            validateDisable: true
		},
		components: {
			'clinic-head': clinicHead,
			'clinic-right': clinicRight,
            'clinic-foot': clinicFoot
		},
		mounted: function () {
		    var _self = this;
		    showHtml();
		    
            //设置导航栏样式
		    document.getElementById("Home").className = "invalid-nav";
		    document.getElementById("OrderExpert").className = "invalid-nav";
		    document.getElementById("DistinctMedical").className = "invalid-nav";
		    document.getElementById("MedicalWiki").className = "invalid-nav";
		    document.getElementById("News").className = "invalid-nav";
		    document.getElementById("AboutUs").className = "invalid-nav";
            //设置登录栏显示状态
		    document.getElementById("RegistBar").style.display = "block";
		    document.getElementById("LoginBar").style.display = "none";

		    var phoneTestTip = document.getElementById("phoneTestTip");
		    var newPwdTip = document.getElementById("newPwdTip");
		    var phoneTest = document.getElementById("phoneTest");
		    var newPwd = document.getElementById("newPwd");
		    var successBox = document.getElementById("successBox");
		    var goRegister = document.getElementById("goRegister");
		    var firstStep = document.getElementById("firstStep");
		    var secondStep = document.getElementById("secondStep");
		    var thridStep = document.getElementById("secondStep");

		    phoneTestTip.style.display = "none";
		    newPwdTip.style.display = "none";
		    goRegister.style.display = "none";
		    CheckLoginStatus(_self, _self.loginInfo);
        },
		methods:{
			//密码是否显示明文
			pswExpress:function(psw,pswPic){
				var pswExpress=document.getElementById(pswPic),
					lPsw=document.getElementById(psw);
				if(pswExpress.className=="noExpress"){
					lPsw.setAttribute("type","text");
					pswExpress.style.background = "url(/styles/image/icon/psw_icon2.png) no-repeat";
					pswExpress.setAttribute("class","yesExpress");
				}else if(pswExpress.className=="yesExpress"){
					lPsw.setAttribute("type","password");
					pswExpress.style.background = "url(/styles/image/icon/psw_icon1.png) no-repeat";
					pswExpress.setAttribute("class","noExpress");
				}
			},
			CodeValidate:function(){
			    var _self = this;
			    _self.nextStepDisable = true;
			    _self.validateDisable = true;
			    if (isEmpty(_self.UserInfo.Mobile)) {
			        return false;
			    }
			    
			    _self.validateDisable = false;
			},

		    //获取验证码
		    getValidateCode: function () {
		        var _self = this;
		        phoneTestTip.style.display = "none";
		        _self.nextStepDisable = true;
		        _self.validateDisable = true;
		        if (!(/^1[34578]\d{9}$/.test(_self.UserInfo.Mobile))) {
		            phoneTestTip.style.display = "block";
		            _self.sChangePwdTip = "请输入正确的手机号！";
		            return false;
		        }
		        _self.validateDisable = false;
		        _self.$http.post("/ForgetPwd/GetValidateCode", _self.UserInfo).then(function(res){
		            _self.p_obj.url = "";
		            _self.p_obj.text = res.body.Msg;
		            dialogTip(_self.p_obj);
		            if (res.body.Code == "1")
		                sendCode(document.getElementById("getValidateCode"));
		        });               
		    },
		    NextStepValidate: function () {
		        var _self = this;
		        _self.nextStepDisable = true;
		        if (isEmpty(_self.UserInfo.Mobile)) {
		            return false;
		        }
		        else if (isEmpty(_self.UserInfo.ValidateCode)) {
		            return false;
		        }
		        _self.nextStepDisable = false;
		    },
		    nextStep: function () {
		        var _self = this;
		        
		        if (!(/^1[34578]\d{9}$/.test(_self.UserInfo.Mobile))) {
		            phoneTestTip.style.display = "block";
		            _self.sChangePwdTip = "请输入正确格式的手机号码";
		            return false;
		        }		        
		        _self.$http.post("/ForgetPwd/GoNextStep",_self.UserInfo).then(function (res) {
		            if (res.body.Code == 1) {
		                phoneTestTip.style.display = "none";
		                phoneTest.style.display = "none";
		                newPwd.style.display = "block";
		                secondStep.className = "iconfont iconfont-active";

		            }
		            else {
		                phoneTestTip.style.display = "block";
                        if(res.body.Code == -1)
		                    goRegister.style.display = "block";
		                _self.sChangePwdTip = res.body.Msg;
		            }
		        });
		    },
		    //返回上一个页面或首页
		    skipBack: function () {
		        if (window.history.length > 1)
		            window.history.back();
		        else
		            window.location.href = "..";
		    },
		    goToHome:function(){
		        window.location.href = "..";
		    },
		    validatePwd:function(){
		        var _self = this;		        
		        _self.sureDisable = true;
		        if (_self.UserInfo.Password == null || _self.UserInfo.Password == "") {
		            return false;
		        }
		        _self.sureDisable = false;
		    },
		    confirmPwdChg: function () {
		        var _self = this;
		        newPwdTip.style.display = "none";
		        if (!(/^[a-zA-Z\d]{8,20}$/.test(_self.UserInfo.Password))) {
		            newPwdTip.style.display = "block";
		            _self.sChangePwdTip = "请设置8~20位的字母或数字为密码";
		            return false;
		        }
		        _self.$http.post("/ForgetPwd/ChangePassword", _self.UserInfo).then(function (res) {
		            if (res.body.Code == 1) {
		                phoneTestTip.style.display = "none";
		                phoneTest.style.display = "none";
		                newPwd.style.display = "none";
		                successBox.style.display = "block";
		                thirdStep.className = "iconfont iconfont-active";
		                //检查登录状态
		                CheckLoginStatus(_self, _self.loginInfo,false);
		                
		            }
		            else {
		                newPwdTip.style.display = "block";
		                phoneTestTip.style.display = "none";
		                _self.sChangePwdTip = res.body.Msg;
		            }
		        });
		    }
		}
	})
})(Vue)